<?php
/**
 * Template Name: login
 *
 * 通用的登录注册
 * date:2011/4/11 
 * @author Ryan 
 * 
 */

get_header();

$register = $_GET['action'];

$templateurl = get_bloginfo('template_url');


?>

<script type="text/javascript">
var tab_label= <?php echo $register == 'register' ? 2 : 1;?>;

var emailError = false;
var passError = false;
var passError2 = false;

function tab_toggle(label)
{
	if (tab_label==label)
	{
	   return;
	}
	document.getElementById("tab_"+tab_label).className="normal_tab";
	document.getElementById("tab_"+label).className="current_tab";
	document.getElementById("contain_"+tab_label).style.display="none";
	document.getElementById("contain_"+label).style.display="";
	tab_label=label;
}

function checkemail(){
	var email = $('#email_input').val();
		if(checkEmailType(email)){
			$.ajax({
			url: "<?php echo $templateurl?>/register_ajax.php",
			data: {'action': 'checkemail', 'value': email},
			success: function (data){
				if(data == '1'){
					$('#emailstatus').html('该邮箱已经注册过！');
					$('#emailstatus').css({'color': 'red'});
					emailError = false;
				}else{
					$('#emailstatus').html('可以使用的邮箱！');
					$('#emailstatus').css({'color': 'green'});
					emailError = true;
				}
			}
			});
		}else{
			$('#emailstatus').html('请使用正确的邮箱格式！');
			$('#emailstatus').css({'color': 'red'});
			emailError = false;
		}
}

function checkPass1(){
	var pass = $('#pass_input1').val();
	if(pass.length < 6){
		$('#passstatus').html('密码应最少6个字符！');
		$('#passstatus').css({'color': 'red'});
		passError = false;
	}else{
		$('#passstatus').html('');
		passError = true;
	}
}

function checkPass2(){
	var pass1 = $('#pass_input1').val();
	var pass2 = $('#pass_input2').val();
	if(pass1 != pass2){
		$('#passstatus2').html('两次输入密码不一致！');
		$('#passstatus2').css({'color': 'red'});
		passError2 = false;
	}else{
		$('#passstatus2').html('');
		passError2 = true;
	}
}

function checkSubmit(){
	return emailError && passError && passError2;
}

function checkEmailType(email){  
    var regInvalid=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;  
    var regValid=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;  
    return (!regInvalid.test(email) && regValid.test(email));  
} 

function login(){
	var username = $('#username_input').val();
	var password = $('#password_input').val();

	$("#login_bt").attr('disabled', 'disabled');
	$("#loginstatus").html('');
	
	$.ajax({
		url: "<?php echo $templateurl?>/register_ajax.php",
		data: {'action': 'login', 'username': username, 'password': password},
		success: function (data){
				if(data == '0'){
					$("#loginstatus").html('登录失败：用户名或密码不正确。');
					$("#loginstatus").css({'color': 'red'});
				}else if(data == '2'){
					$("#loginstatus").html('登录失败：用户名不存在。');
					$("#loginstatus").css({'color': 'red'});
				}else if(data){
					$("#login_form").submit();
				}

				$("#login_bt").removeAttr('disabled');
			}	
		});
}

function keyLogin(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	if (keyCode == 13) {
	    login();
	}
}
/*
WB2.login(function(){
	//callback function
	alert("dddddd");
});
*/




</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1027418428;
var google_conversion_language = "ar";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "vSLWCLSbqAIQvNL06QM";
var google_conversion_value = 0;
/* ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1027418428/?label=vSLWCLSbqAIQvNL06QM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>
		<div id="zc">
        	<div style="background:#fff; float:left;">
                <DIV id="tab_container"> 
                    <UL id="navpyra">
                    <LI class="<?php echo $register == 'register' ? 'normal_tab' : 'current_tab'; ?>" id="tab_1"><A onclick="tab_toggle(1)" href="javascript:void(0)" rel="nofollow">账号登录</A> </LI>
                    <LI class="<?php echo $register == 'register' ? 'current_tab' : 'normal_tab'; ?>" id="tab_2"><A onclick="tab_toggle(2)" href="javascript:void(0)" rel="nofollow">会员注册</A> </LI> 
                    </UL>
                </DIV> 
                <DIV id="tab_contain" > 
                    <DIV id="contain_1" style="display: <?php echo $register == 'register' ? 'none' : 'block'; ?>;">
                        <form id="login_form" action="/loginsuccess" method="post">
                            <table>
                            	<tr>
                            		<td colspan="3"><p id="loginstatus"></p></td>
                            	</tr>
                                <tr>
                                    <td valign="middle">邮&nbsp;&nbsp;&nbsp;&nbsp;箱：</td>
                                    <td><input type="text" id="username_input" name="username" class="inputstyle02 inputstyle" />
                                    	
                                    </td> 
                                    <td >
                                    	<div style="padding-left: 50px;">
                                    	<span id="wb_connect_btn">
                                    	</span>
                                    	<!-- 
                                    		<a href="javascript:void(0)" >
                                    			<img id="wb_connect_btn" alt="" src="<?php echo $templateurl."/images/sina.png"?>" /></a>
                                    	 -->
                                    	</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="middle">密&nbsp;&nbsp;&nbsp;&nbsp;码：</td>
                                    <td colspan="2"><input type="password" id="password_input" name="password" class="inputstyle02 inputstyle" onkeydown="keyLogin(event)" />
                                    <input type="hidden" name="url_refrence" value="<?php echo $_SERVER['HTTP_REFERER'];?>" />
                                    <input id="login_type_input" type="hidden" name="login_type" value="normal" />
                                    <input id="login_type_name" type="hidden" name="out_name" value="normal" />
                                    <input id="login_type_id" type="hidden" name="out_id" value="normal" />
                                    </td> 
                                </tr>
                                <tr>
                                    <td colspan="2"><input type="button" value="点击登录" id="login_bt" class="inputstyle03" onclick="login()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="button" value="会员注册" id="login_bt" class="inputstyle03"onclick="tab_toggle(2)" href="javascript:void(0)" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
                                    </td> 
                                </tr>
                            </table>
                        </form> 
 
                    </DIV> 
                    <DIV id="contain_2" style="display: <?php echo $register == 'register' ? 'block' : 'none'; ?>;">
                        <form action="/registersuccess" method="post" onsubmit="return checkSubmit();">
                            <table>
                                <tr>
                                    <td valign="middle">邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱：</td>
                                    <td><input type="text" id="email_input" name="email" class="inputstyle02 inputstyle" onblur="checkemail();"/></td> 
                                    <td><p id="emailstatus"></p></td>
                                </tr>
                                <tr>
                                    <td valign="middle">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</td>
                                    <td><input type="password" id="pass_input1" name="password" class="inputstyle02 inputstyle" onblur="checkPass1()" /></td>
                                    <td><p id="passstatus">密码应大于6位字符。</p></td>
                                </tr>
                                <tr>
                                    <td valign="middle">确认密码：</td>
                                    <td><input type="password" id="pass_input2" name="password" class="inputstyle02 inputstyle" onblur="checkPass2()" /></td> 
                                    <td><p id="passstatus2"></p></td>
                                </tr>
                                <tr>
                                    <td valign="middle">昵&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称：</td>
                                    <td><input type="text" name="display_name" class="inputstyle02 inputstyle" /></td> 
                                </tr>
                                <tr>
                                    <td valign="middle">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</td>
                                    <td>
                                    	<input type="radio" name="user_sex"  value="男" checked="checked"/>男 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                     	<input type="radio" name="user_sex" value="女" />女
                                    </td>
                                </tr>
                                 <tr>
                                    <td valign="middle">生&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日：</td>
                                    <td>
                                    <select name="user_birth_year" class="inputstyle01 inputstyle">
                                    	<?php for($i=1900; $i<2011; $i++ ){
                                    		echo '<option value="'.$i.'" >'.$i."</option>";
                                    	}?>
                                    </select>年 &nbsp;&nbsp;
                                    <select name="user_birth_month" class="inputstyle01 inputstyle">
                                    	<?php for($i=1; $i<13; $i++ ){
                                    		echo '<option value="'.$i.'" >'.$i."</option>";
                                    	}?>
                                    </select>月
                                    
                                    </td> 
                                </tr>
                                <tr>
	                                <td><label for="yanzheng" style="float:left">验证码:&nbsp;</label></td>
				                   	<td><input type="text" name="yz" class="inputstyle02 inputstyle" /></td>
				                    <td><img src="<?php echo $templateurl ?>/verify.php"  onclick="this.src='<?php echo $templateurl ?>/verify.php/'+Math.random()*5;" style="cursor:pointer" alt="验证码,看不清楚?请点击刷新验证码" title="验证码,看不清楚?请点击刷新验证码" id="checkCode" class="code" /></td>
                                </tr> 
                                <tr>
                                    <td valign="middle"> </td>
                                    <td><input type="submit" value="提交注册" class="inputstyle03" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    </td> 
                                </tr>
                            </table>
                        </form> 
                    </DIV> 
                </DIV>	
            </div>
        </div> 
        
 <?php get_footer();?>